package com.jiaoyou.baojian.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiaoyou.baojian.R;

/**
 * Created by DemonZYM on 17/5/6.
 */

public class ImageSelectDialog {
    private Dialog imageSelectDialog;

    public ImageSelectDialog(Context context, final OnImageSelectListener listener){
        View view = LayoutInflater.from(context).inflate(
                R.layout.dialog_select_image, null);
        Button cameraBtn = (Button) view.findViewById(R.id.camera);
        Button galleryBtn = (Button) view.findViewById(R.id.gallery);
        cameraBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
                if(listener != null)
                    listener.onSelectCamera();
            }
        });
        galleryBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
                if(listener != null)
                    listener.onSelectGallery();
            }
        });
        // 创建自定义样式的Dialog
        imageSelectDialog = new Dialog(context, R.style.loading_dialog);
        imageSelectDialog.setCancelable(true);
        imageSelectDialog.setContentView(view, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));
    }

    public void show(){
        imageSelectDialog.show();
    }

    public void close(){
        if (imageSelectDialog != null) {
            imageSelectDialog.dismiss();
        }
    }

    public interface OnImageSelectListener{
        public void onSelectCamera();
        public void onSelectGallery();
    }
}
